/*
#####################################################################
####################	   T R I B U I T 		#####################
#####################################################################

Copyright (C) 2010  Christoph Schnack, Berlin (Germany)

This file is part of Tribuit.

    Tribuit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Tribuit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Tribuit.  If not, see <http://www.gnu.org/licenses/>.


########################################################################
*/
package Mainframe;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JButton;

public class ExtendButton extends JButton{
	Color color=Color.gray;
	Color hoveredColor = Color.red;
	Color currentColor = color;
	JButton btn;
	boolean start=true;
	String buttonText="";
	/**
	 * 
	 * @param op button text
	 */
	public ExtendButton(String buttonTextArg, Color colorArg,Color colorHoveredArg){
		super();
		buttonText = buttonTextArg;
		color = colorArg;
		hoveredColor = colorHoveredArg;
		currentColor = color;
		buildButton();
	}
	
	public ExtendButton(String buttonTextArg){
		super();
		buttonText=buttonTextArg;
		buildButton();
	}
	
	public void buildButton(){
		btn=this;
		this.setBorder(null);
		this.setUI(null);
		this.addFocusListener(new FocusListener(){

			public void focusGained(FocusEvent arg0) {
				color=Color.red;
			}
			
			public void focusLost(FocusEvent arg0) {
				color=Color.gray;
			}
			
		});
		this.addMouseListener(new MouseListener(){

			public void mouseClicked(MouseEvent e) {
				btn.doClick();
			}

			public void mouseEntered(MouseEvent e) {
				currentColor = hoveredColor;
				repaint();
			}

			public void mouseExited(MouseEvent e) {
				currentColor = color;
				repaint();
			}

			public void mousePressed(MouseEvent e) {}
			public void mouseReleased(MouseEvent e) {}
		});
		this.setPreferredSize(new Dimension(30,15));
		this.setOpaque(false);
	}
	
	public String getButtonText(){
		return buttonText;
	}
	
	public void setButtonText(String txt){
		buttonText = txt;
		this.repaint();
	}
	
	public void paintComponent(Graphics g){
		g.setColor(currentColor);
		g.setFont(new Font(g.getFont().getFamily(),Font.PLAIN,9));
		g.drawString(buttonText,5,9);
	}
}